package com.muki.succ.web.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.muki.succ.web.service.UriService;
import com.muki.uri.core.SpiderUriMemoryCache;
import com.muki.uri.core.UriRegisterationCore;

@Service
public class UriServiceImpl implements UriService {

	Map<String,List<String>> using = new HashMap<>();
	List<String> unusing = new ArrayList<>();
	
	
	
	@Override
	public boolean registeryStartUri(String topic, String url) {
		try {
			UriRegisterationCore.getSpiderRunning(topic, url);
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	@Override
	public List<String> getAlls(String topic) {
		return SpiderUriMemoryCache.getUrls(topic);
	}

	@Override
	public int complete(String topic) {
		List<String> urls = SpiderUriMemoryCache.getUrls(topic);
		if(urls==null)
			return 0;
		return urls.size();
	}

	@Override
	public Map<String, List<String>> getUsingUrls() {
		return UriRegisterationCore.getUriCollection();
	}

}
